<?php
declare (strict_types = 1);

namespace app\model;

use think\Model;
use think\model\relation\HasOne;

/**
 * @mixin \think\Model
 */
class AdminStudentParents extends Model
{
    //
    const AUDIT_WAITING = 0; // 待审核
    const AUDIT_PASS = 1;   // 审核通过
    const AUDIT_REFUSE = 2; // 审核拒绝


    protected $autoWriteTimestamp = true;

    public function school() {
        return $this->belongsTo(AdminSchool::class, 'school_id')
            ->where('is_delete', 0)->bind([
            'school_name' => 'name'
        ]);
    }

    public function staff() {
        return $this->belongsTo(AdminStaff::class, 'staff_id')
            ->where('is_delete', 0)->bind([
                'student_name' => 'name',
                'student_sex' => 'sex',
                'student_uuid' => 'uuid',
                'avatar_url',
                'entrance_time',
                'graduate_time',
                'phone',
                'avatar_url'
            ]);
    }

    public function parent() {
        return $this->belongsTo(AdminParents::class, 'parent_id')
            ->where('is_delete', 0)->bind([
                'parent_name' => 'name',
                'parent_phone' => 'phone',
                'parent_sex' => 'sex',
            ]);
    }

    public function getAuditTimeAttr($value,$data)
    {
        return $data['audit_time'] > 0 ? date('Y-m-d H:i:s', $data['audit_time']) : '';
    }

}
